package com.ch03;

/*
 * This class illustrates overloading
 */
public class Overloading {
	private int add(int n, int m) {
		System.out.println("Adding 2 integers");
		return n+m;
	}
	
	private double add(double a, double b) {
		System.out.println("Adding 2 doubles");
		return a+b;
	}
	
	private double add(float a, float b) {
		System.out.println("Adding 2 floats");
		return a+b;
	}
	
	private int add(String s, String s2) {
		System.out.println("Adding 2 Strings");
		int sum = 0;
		int no1 = 0, no2 = 0;
		try {
			no1 = Integer.parseInt(s);
			no2 = Integer.parseInt(s2);
		} catch (NumberFormatException e) {
			
		}
		return no1+no2;
	}
	
	public static void main(String args[]) {
		Overloading obj = new Overloading();
		System.out.println(obj.add(1,2));
		System.out.println(obj.add(10.1,2.2));
		System.out.println(obj.add(10,2.5));
		System.out.println("----------------");
		System.out.println(obj.add(30f,3.5f));
		System.out.println(obj.add(30d,2.5f));
		System.out.println("----------------");
		System.out.println(obj.add("20","40"));
	}
}
